clear all
*Define directory
cap cd "...\Replication pacakage\"



*merge map data with COVID EIDL in 2021
use _ID _CX _CY fips STATEFP using usacnty.dta, clear
merge m:m fips using county_COVIDEIDL.dta
drop if _merge == 2
drop _merge

drop if stateabbrv=="AS"| stateabbrv=="GU" | stateabbrv=="MP" | stateabbrv=="PR" | stateabbrv=="VI" | stateabbrv=="HI" | stateabbrv=="AK"
drop if STATEFP=="02"|STATEFP=="15"|STATEFP=="60"|STATEFP=="69"||STATEFP=="72"|STATEFP=="78"

keep if _CX>-125&_CX<-66
keep if _CY>24 & _CX<50

replace COVIDEIDLpercap=0 if COVIDEIDLpercap==.

grmap COVIDEIDLpercap,legenda(on) clmethod(custom) cln(4) clb(0 100 500 1000 10000) osize(vvthin vvthin vvthin vvthin) fc(OrRd) legtitle("COVID EIDL loans amount per capita in 2020 ($)") 
graph export "Figure 3\Figure 3c_COVIDEIDL_county_loanamountpercap.pdf", as(pdf) replace


*merge map data with EIDL (2003-2020)
use _ID _CX _CY fips STATEFP using usacnty.dta, clear
merge m:m fips using county_EIDL.dta
drop if _merge == 2
drop _merge

drop if stateabbrv=="AS"| stateabbrv=="GU" | stateabbrv=="MP" | stateabbrv=="PR" | stateabbrv=="VI" | stateabbrv=="HI" | stateabbrv=="AK"
drop if STATEFP=="02"|STATEFP=="15"|STATEFP=="60"|STATEFP=="69"||STATEFP=="72"|STATEFP=="78"

keep if _CX>-125&_CX<-66
keep if _CY>24 & _CX<50

replace N=0 if N==.
replace EIDLpercap=0 if EIDLpercap==.
*Annual average loan amount percap 2003-2020
replace EIDLpercap=EIDLpercap/18

grmap EIDLpercap,legenda(on) clmethod(custom) cln(4) clb(0 0.01 0.1 1 100) osize(vvthin vvthin vvthin vvthin) fc(OrRd) legtitle("Average annual EIDL loans amount per capita between 2003 and 2020 (in 2020 dollars)") legend(label(5 "(1, 100]") label(4 "(0.1, 1]") label(3 "(0.01, 0.1]") label(2 "[0, 0.01]"))
graph export "Figure 3\Figure 3b_EIDL_county_loanamountpercap.pdf", as(pdf) replace


*merge map data with BPDL (2003-2020)
use _ID _CX _CY fips STATEFP using usacnty.dta, clear
merge m:m fips using county_BPDL.dta
drop if _merge == 2
drop _merge

drop if stateabbrv=="AS"| stateabbrv=="GU" | stateabbrv=="MP" | stateabbrv=="PR" | stateabbrv=="VI" | stateabbrv=="HI" | stateabbrv=="AK"
drop if STATEFP=="02"|STATEFP=="15"|STATEFP=="60"|STATEFP=="69"||STATEFP=="72"|STATEFP=="78"

keep if _CX>-125&_CX<-66
keep if _CY>24 & _CX<50

replace BPDLpercap=0 if BPDLpercap==.
*Annual average loan amount percap 2003-2020
replace BPDLpercap=BPDLpercap/18


grmap BPDLpercap,legenda(on) clmethod(custom) cln(4) clb(0 0.01 0.1 1 100) osize(vvthin vvthin vvthin vvthin) fc(OrRd) legtitle("Average annual BPDL loans amount per capita between 2003 and 2020 (in 2020 dollars)") legend(label(5 "(1, 100]") label(4 "(0.1, 1]") label(3 "(0.01, 0.1]") label(2 "[0, 0.01]"))
graph export "Figure 3\Figure 3a_BPDL_county_loanamountpercap.pdf", as(pdf) replace

